package com.wcy.controller.perm;

import com.wcy.annotation.aop.PreAuth;
import com.wcy.entity.Role;
import com.wcy.entity.RolePermission;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.perm.FeignRolePermissionService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class RolePermissionController {
    @Resource
    private FeignRolePermissionService feignRolePermissionService;


    @GetMapping("rolePermission/page")
    public ResponseEntity<PageData<RolePermission>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                            @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(RolePermission.class, Objects.requireNonNull(feignRolePermissionService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("rolePermission/add", "rolePermission/update", "rolePermission/delete"), ColumnConstructor.create()));
    }

    @GetMapping("rolePermission/list")
    public ResponseEntity<List<RolePermission>> getList(){
        return feignRolePermissionService.getList();
    }

    @PostMapping("rolePermission/add")
    public ResponseEntity<Void> add(@RequestBody RolePermission rolePermission){
        return feignRolePermissionService.add(rolePermission);
    }

    @PutMapping("rolePermission/update")
    public ResponseEntity<Void> update(@RequestBody RolePermission rolePermission){
        return feignRolePermissionService.update(rolePermission);
    }

    @DeleteMapping("rolePermission/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id){
        return feignRolePermissionService.delete(id);
    }
}
